import * as parse5 from "parse5";

const document = parse5.parse(
  "<!DOCTYPE html><html><head></head><body>Hi there!</body></html>",
);
/**
 * @param {import('parse5').DefaultTreeAdapterTypes.ChildNode} node
 * @returns {node is import('parse5').DefaultTreeAdapterTypes.Element | import('parse5').DefaultTreeAdapterTypes.Template}
 */
const isElementNode = (node) =>
  node.nodeName !== "#text" &&
  node.nodeName !== "#comment" &&
  node.nodeName !== "#documentType";

const [, documentElement] = document.childNodes;

console.log(
  isElementNode(documentElement)
    ? documentElement.nodeName
    : documentElement.nodeName,
); // > 'html'
